package client.based.location.lbs;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.google.gson.Gson;

import java.util.zip.GZIPOutputStream;

import client.based.location.lbs.network.JsonRequestClass;
import client.based.location.lbs.network.NetworkUtil;
import client.based.location.lbs.network.ResponseListner;
import client.based.location.lbs.responsemodel.ResponseBasedModel;


public class LauncherActivity extends FragmentActivity  implements View.OnClickListener,ResponseListner{
private EditText mPasswordEditText,mEmailEditText;
private Button mButton;
private TextView mRegisterTextView;
private boolean isNetworkPresent;
    private NetworkUtil networkUtil;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_launcher);
        init();



        networkUtil=new NetworkUtil(getApplicationContext());
        isNetworkPresent= networkUtil.isConnectingToInternet();
        if(isNetworkPresent)
        {
            new JsonRequestClass(LauncherActivity.this).makerequest(LauncherActivity.this,"");
        }
    }

    private void init() {
        mPasswordEditText= (EditText) findViewById(R.id.etPass);
        mEmailEditText= (EditText) findViewById(R.id.etUserName);
        mButton= (Button) findViewById(R.id.btnSingIn);
        mRegisterTextView= (TextView) findViewById(R.id.signUpTextView);
        mButton.setOnClickListener(this);
        mRegisterTextView.setOnClickListener(this);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_launcher, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onClick(View v) {
       switch (v.getId())
       {
           case R.id.btnSingIn:
           {if(isNetworkPresent)
           {
               new JsonRequestClass(LauncherActivity.this).makerequest(LauncherActivity.this,"");
           }}

       }


    }

    @Override
    public void onGetResponse(String res) {
       try {
           ResponseBasedModel responseBasedModel = new ResponseBasedModel();
           responseBasedModel = new Gson().fromJson(res, responseBasedModel.getClass());
      if(responseBasedModel.getError())
      {
          Log.i("response",""+responseBasedModel.toString());
      }else{
          Log.i("response",""+responseBasedModel.toString());
      }
       }catch (Exception e)
       {}

    }
}
